package com.itianyu.blog.dao.implementations;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itianyu.blog.dao.beans.Comment;
import com.itianyu.blog.dao.beans.Tag;
import com.itianyu.blog.dao.interfaces.CommentInterface;
@Service
public class CommentImplementation implements CommentInterface{
	private static final long serialVersionUID = 1L;

	@PersistenceContext
	private EntityManager em;

	@Override
	public List<Comment> findCommentEntities(int entryId) {
		// TODO Auto-generated method stub
		Query q = em.createQuery("SELECT OBJECT(t) FROM Comment t where t.entryid='"+entryId+"' ORDER BY t.id desc");
		List<Comment> items = q.getResultList();
		return items;
	}


	@Transactional
	public Comment save(Comment comment) {
		return em.merge(comment);
		
	}

}
